package me.fung.wubi.base.define.value


object CodeList {
    private val letters = arrayOf(
        ' ',
        'a', 'b', 'c', 'd', 'e',
        'f', 'g', 'h', 'i', 'j',
        'k', 'l', 'm', 'n', 'o',
        'p', 'q', 'r', 's', 't',
        'u', 'v', 'w', 'x', 'y',
        // 'z',
    )

    var value: List<String> = createCodeList()

    private fun createCodeList(): List<String> {
        val temp = ArrayList<String>()
        val indices = IntArray(4) { 0 }
        while (move(indices)) {
            var str = ""
            for (i in indices.indices) {
                if (indices[i] != 0) {
                    str += letters[indices[i]]
                }
            }
            temp.add(str)
        }
        temp.sorted()
        return temp
    }

    //移动索引：order表示第几个索引
    private fun move(indices: IntArray, order: Int = 3): Boolean {
        if (order < 0) {
            return false
        }
        indices[order] = indices[order] + 1
        //索引位置超出长度，重置到第一个字母，并移动前一位索引
        if (indices[order] == letters.size) {
            indices[order] = 1
            return move(indices, order - 1)
        }
        return true
    }
}
